$("#treatmentUnitBox").on('click', '.projectDatas', function() {
    $(this).parent().parent().find(".pay_list_c1").css("background", "#DCDCDC");
    $(this).children().attr('checked', 'true');
    $(this).css("background", "#289bd6")
});
$("#treatmentUnitBox").on('click', '.projectData', function() {
    $(this).parent().parent().find(".pay_list_c1").css("background", "#DCDCDC");
    $(this).siblings().css("background", "#289bd6")
});

//根据科室获取一级项目
function getFirstLevelProjectByTreatmentUnit(treatmentUnit) {
    var customerId = $('#customerId').val();
    $("#treatmentUnit").val(treatmentUnit);
    var dc = treatmentUnit + "," + customerId;
    $.ajax({
        url: Feng.ctxPath + "/payService/getFirstLevelProject",
        type: "post",
        data: {"dc": dc},
        success: function (data) {
            var txt = '';
            for (var i = 0; i < data.length; i++) {
                txt += ' <option value="' + data[i].firstLevelProject + '"> ' + ' &nbsp' + data[i].firstLevelProject + '</option>';
            }
            document.getElementById('firstLevelProjectDivsd').innerHTML = txt;
            openFirstLevelProject();
        },
        error: function (data) {
            alert('没有权限，请联系系统管理员!');
            parent.layer.close(windowNameIndex);
        }
    });
}

$("#submission").click(function() {
    if (confirm("是否确认提交修改科室？")) {
        var initialization = $("input[name='about']:checked").val();
        var customerId = $("#customerId").val();
        var remarks = $("#remarks").val();
        var treatmentUnitY = $("#treatmentUnitValue").val();
        if (initialization == "" || initialization == null) {
            alert("请选择一个科室！");
            return
        }
        $.ajax({
            url: Feng.ctxPath + "/customer/treatmentUnitGrade",
            type: "post",
            data: {
                "initialization": initialization,
                "customerId": customerId,
                "treatmentUnitY": treatmentUnitY,
                "remarks": remarks
            },
            success: function(data) {
                if (data == 1) {
                    if (remarks == "" || remarks == null) {
                        alert("请填写变更理由！");
                        return
                    }
                }
                $.ajax({
                    url: Feng.ctxPath + "/customer/update_TreatmentUnitValue1",
                    type: "post",
                    data: {
                        "initialization": initialization,
                        "customerId": customerId,
                        "treatmentUnitY": treatmentUnitY,
                        "remarks": remarks
                    },
                    success: function(data) {
                        if (data == 1) {
                            Feng.success("已提交变更科室申请，请联系审批人!");
                            parent.layer.close(parent.layer.getFrameIndex(window.name))
                        } else {
                            Feng.success("科室变更成功!");
                            $("#treatmentUnitHtml", parent.document).text(initialization);
                            $("#treatmentUnit", parent.document).val(initialization);
                            getFirstLevelProjectByTreatmentUnit(initialization);
                            if (initialization != "") {
                                $("#treatmentUnitTwo option[value=" + initialization + "]", parent.document).attr("selected", "selected")
                            }
                            if(parent.$("#detail").val()=='isArrive') {
                                parent.location.href = Feng.ctxPath + '/consultantDetails/consultantToDetailByTab/' + customerId + '/1/0';
                            }else{
                                parent.location.href = Feng.ctxPath + '/consultantDetails/consultantToDetailByTab/' + customerId + '/2/0';
                            }
                            parent.layer.close(parent.layer.getFrameIndex(window.name))
                        }
                    }
                })
            }
        })
    }
});